package com.ruoyi.common.enums.wecom;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum WecomChatGroupUserTypeEnum {


    /**
     * 用户类型枚举
     * 1 - 企业成员
     * 2 - 外部联系人
     */
    INTERNAL_MEMBER(1, "企业成员"),
    EXTERNAL_CONTACT(2, "外部联系人");

    private final Integer code;
    private final String desc;

    /**
     * 根据code获取枚举
     */
    public static WecomChatGroupUserTypeEnum getByCode(Integer code) {
        for (WecomChatGroupUserTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 根据desc获取枚举
     */
    public static WecomChatGroupUserTypeEnum getByDesc(String desc) {
        for (WecomChatGroupUserTypeEnum type : values()) {
            if (type.getDesc().equals(desc)) {
                return type;
            }
        }
        return null;
    }

    /**
     * 检查code是否存在
     */
    public static boolean contains(Integer code) {
        return getByCode(code) != null;
    }
}
